package com.example.demoex;

import com.kris.search.SearchFlyActivity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;


public class Welcome_Guide extends Activity {
	private ImageView mShowPicture;
	private TextView mShowText;
	private Button mRegister;
	private Button mWhoIKnow;
	private Button mLogin;

	private Animation mFadeIn;
	private Animation mFadeInScale;
	private Animation mFadeOut;

	private Drawable mPicture_1;
	private Drawable mPicture_2;
	private Drawable mPicture_3;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.welcome_guide);
		findViewById();
		init();
		setListener();
	}

	private void findViewById() {
		mShowPicture = (ImageView) findViewById(R.id.guide_picture);
		mShowText = (TextView) findViewById(R.id.guide_content);
		mRegister = (Button) findViewById(R.id.guide_register);
		mWhoIKnow = (Button) findViewById(R.id.guide_who_i_know);
		mLogin = (Button) findViewById(R.id.guide_login);
	}
/*	　　1)学会懒惰
	　　aDon"t Reinvent the Wheel(不要重复发明轮子)。
	　　bInventing the Wheel(发明轮子)。
	　　cDon"t Reinvent the Wheel(不要重复发明轮子)。
	　　“轮子理论”，也即“不要重复发明轮子”，这是西方国家的一句谚语，原话是：Don"t Reinvent the Wheel。“不要重复发明轮子 ”意思是企业中任何一项工作实际上都有人做过，我们所需要做的就是找到做过这件事情的人。拿到软件领域中就是指有的项目或功能，别人已经做过，我们需要用的时候，直接拿来用即可，而不要重新制造。
	　　2)精通Android体系架构、MVC、常见的设计模式、控制反转(IoC)
	　　3)编写可重用、可扩展、可维护、灵活性高的代码
	　　4)高效的编写高效的代码
	　　5)学会至少一门服务器端开发技术*/

	private void setListener() {

		mFadeIn.setAnimationListener(new AnimationListener() {

			public void onAnimationStart(Animation animation) {

			}

			public void onAnimationRepeat(Animation animation) {

			}

			public void onAnimationEnd(Animation animation) {
				mShowPicture.startAnimation(mFadeInScale);
			}
		});
		mFadeInScale.setAnimationListener(new AnimationListener() {

			public void onAnimationStart(Animation animation) {

			}

			public void onAnimationRepeat(Animation animation) {

			}

			public void onAnimationEnd(Animation animation) {
				mShowPicture.startAnimation(mFadeOut);
			}
		});
		mFadeOut.setAnimationListener(new AnimationListener() {

			public void onAnimationStart(Animation animation) {

			}

			public void onAnimationRepeat(Animation animation) {

			}

			public void onAnimationEnd(Animation animation) {

				if (mShowPicture.getDrawable().equals(mPicture_1)) {
					mShowText.setText("ͬ1)学会懒惰");
					mShowPicture.setImageDrawable(mPicture_2);
				} else if (mShowPicture.getDrawable().equals(mPicture_2)) {
					mShowText.setText("2)精通Android体系架构、MVC、常见的设计模式、控制反转(IoC)");
					mShowPicture.setImageDrawable(mPicture_3);
				} else if (mShowPicture.getDrawable().equals(mPicture_3)) {
					mShowText.setText("3)编写可重用、可扩展、可维护、灵活性高的代码");
					mShowPicture.setImageDrawable(mPicture_1);
				}
				mShowPicture.startAnimation(mFadeIn);
			}
		});
		mRegister.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
//				Toast.makeText(Welcome_Guide.this, "mRegister",
//						Toast.LENGTH_SHORT).show();
				startActivity(new Intent(Welcome_Guide.this, DemoCollectionMainActivity.class));
//				finish();
			}
		});
		mWhoIKnow.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
//				Toast.makeText(Welcome_Guide.this, "mWhoIKnow",
//						Toast.LENGTH_SHORT).show();
				startActivity(new Intent(Welcome_Guide.this, SearchFlyActivity.class));
				finish();
			}
		});
		mLogin.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				startActivity(new Intent(Welcome_Guide.this, DemoExMainActivity.class));
				finish();
			}
		});
	}

	private void init() {
		initAnim();
		initPicture();

		mShowPicture.setImageDrawable(mPicture_1);
		mShowText.setText("高效的编写高效的代码");
		mShowPicture.startAnimation(/*mFadeIn*/mFadeInScale);
	}

	private void initAnim() {
		mFadeIn = AnimationUtils.loadAnimation(Welcome_Guide.this,
				R.anim.v5_0_1_guide_welcome_fade_in);
		mFadeIn.setDuration(1000);
		mFadeInScale = AnimationUtils.loadAnimation(Welcome_Guide.this,
				R.anim.v5_0_1_guide_welcome_fade_in_scale);
		mFadeInScale.setDuration(6000);
		mFadeOut = AnimationUtils.loadAnimation(Welcome_Guide.this,
				R.anim.v5_0_1_guide_welcome_fade_out);
		mFadeOut.setDuration(2000);
	}

	private void initPicture() {
		mPicture_1 = getResources().getDrawable(R.drawable.v5_0_1_guide_pic1);
		mPicture_2 = getResources().getDrawable(R.drawable.v5_0_1_guide_pic2);
		mPicture_3 = getResources().getDrawable(R.drawable.v5_0_1_guide_pic3);
	}
}
